package rmmk.zadanie2;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class PlotWriter {

	String catalog = "spr2/";
	String plotFilename = "plot.txt";
	BufferedWriter late;
	
	public PlotWriter(ISearch s, int endSize, double whichElement) {
		try {
			File plotFile = new File(catalog + "e" + whichElement + "size" + endSize
					+ s.getClass().getSimpleName() + plotFilename);

			if (!plotFile.exists())
				plotFile.createNewFile();

			FileWriter lf = new FileWriter(plotFile.getAbsoluteFile());
			late = new BufferedWriter(lf);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void log(int size, long shortestTime) {
		try {
			late.write(size + " " + shortestTime);
			late.newLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void end() {
		try {
			late.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
